package com.item.controller;


import com.item.domain.TbVideo;
import com.item.po.TbVideoPo;
import com.item.service.TbVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;

@RestController
public class TbVideoController {

    @Autowired
    TbVideoService tbVideoService;

    @PostMapping(value = "/tbVideo/{limit}/{page}")
    public List<TbVideoPo> TbVideo(
            @PathVariable(value = "limit", required = false) int limit,
            @PathVariable(value = "page", required = false) int page,
            @RequestBody(required = false) TbVideo tbVideo) {
        List<TbVideoPo> tbVideos = tbVideoService.findAll(limit, page, tbVideo);
        Collections.shuffle(tbVideos);

        return tbVideos;
    }

    @PostMapping(value = "/tbVideo/add")
    public Integer TbVideoAdd(@RequestBody TbVideo tbVideo) {

        int i = tbVideoService.add(tbVideo);
        return i;
    }

    @PutMapping(value = "/tbVideo/update")
    public Integer tbVideoUpdate(@RequestBody TbVideo tbVideo) {

        int i = tbVideoService.update(tbVideo);
        return i;
    }

    @DeleteMapping(value = "/tbVideo/{id}")
    public Integer tbVideoDelete(@PathVariable(value = "id") int id) {

        int i = tbVideoService.delete(id);
        return i;
    }

}
